import React, {Component} from 'react';

class Content extends  Component{

    componentDidMount() {
        //不能用componentDidMount
        //因为初始化只执行一次
        if(this.props.type===1){
            //正在
            console.log('正在')
        }else {
            //即将
            console.log('即将')
        }
    }

    UNSAFE_componentWillReceiveProps (nextProps, nextContext) {
        console.log(nextProps)
        console.log(nextContext)
    }

    render() {
        return(
            <div>
                Content{this.props.type}
            </div>
        )
    }
}


class App extends Component {
    state={
        type:1
    }
    render() {
        return (
            <div>
                <ul>
                    <button onClick={()=>{
                        this.setState({
                            type:1
                        })
                    }}>正在</button>
                    <button onClick={()=>{
                        this.setState({
                            type:2
                        })
                    }}>即将</button>
                </ul>

                <Content type={this.state.type}></Content>
            </div>
        );
    }
}

export default App;